﻿using Corina.DataContext.Master;
using Corina.Datamodel.DataObject;
using Corina.Datamodel.Entities;
using Corina.Enumerations;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;

namespace Corina.Webservice.Cydee
{
    /// <summary>
    /// Summary description for Weburl
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    // [System.Web.Script.Services.ScriptService]
    public class Weburl : WebserviceBase
    {

        #region Topurl
        [WebMethod]
        public ResultInfo GetAllTopurl(string account, string password, string title, PlatformTypeValue platform)
        {
            return GetInstance<WeburlTopMaster>().GetAllTopurl(account, password, title, platform);
        }

        [WebMethod]
        public ResultInfo InsertTopurl(string account, string password, string title, string url, string icon, string identifyCode, PlatformTypeValue platform, int index, bool showToAll)
        {
            WeburlTopInfo entity = new WeburlTopInfo()
            {
                Title = title,
                Icon = icon,
                Url = url,
                IdentifyCode = identifyCode,
                PlatformType = platform,
                Index = index,
                ShowToAll = showToAll
            };

            return GetInstance<WeburlTopMaster>().Update(account, password, entity, EntityOperation.Insert);

        }

        [WebMethod]
        public ResultInfo UpdateTopurl(string account, string password, string title, string url, string icon, string identifyCode, int index, bool showToAll, int id)
        {
            WeburlTopInfo entity = new WeburlTopInfo()
            {
                Title = title,
                Icon = icon,
                Url = url,
                Id = id,
                IdentifyCode = identifyCode,
                Index = index,
                ShowToAll = showToAll
            };

            return GetInstance<WeburlTopMaster>().Update(account, password, entity, EntityOperation.Update);
        }

        [WebMethod]
        public ResultInfo RemoveTopurl(string account, string password, int id)
        {
            WeburlTopInfo entity = new WeburlTopInfo()
            {
                Id = id
            };

            return GetInstance<WeburlTopMaster>().Update(account, password, entity, EntityOperation.Delete);
        }
        #endregion

        #region Weburl
        [WebMethod]
        public ResultInfo GetAllSuburl(string account, string password, string title, PlatformTypeValue platform)
        {
            return GetInstance<WeburlMaster>().GetAllWeburl(account, password, title, platform);
        }

        [WebMethod]
        public ResultInfo InsertSuburl(string account, string password, string title, string url, string pageCode, int topurlId, int categoryId, int index, bool showToAll)
        {
            WeburlInfo entity = new WeburlInfo()
            {
                Title = title,
                ShowToAll = showToAll,
                CategoryId = categoryId,
                TopurlId = topurlId,
                Icon = "",
                Url = url,
                PageCode = pageCode,
                Index = index
            };

            return GetInstance<WeburlMaster>().Update(account, password, entity, EntityOperation.Insert);
        }

        [WebMethod]
        public ResultInfo UpdateSuburl(string account, string password, string title, string url, string pageCode, int topurlId, int categoryId, int index, bool showToAll, int id)
        {
            WeburlInfo entity = new WeburlInfo()
            {
                Title = title,
                ShowToAll = showToAll,
                CategoryId = categoryId,
                TopurlId = topurlId,
                Icon = "",
                Url = url,
                PageCode = pageCode,
                Index = index,
                Id = id
            };

            return GetInstance<WeburlMaster>().Update(account, password, entity, EntityOperation.Update);
        }

        [WebMethod]
        public ResultInfo RemoveSuburl(string account, string password, int id)
        {
            WeburlInfo entity = new WeburlInfo()
            {
                Id = id
            };

            return GetInstance<WeburlMaster>().Update(account, password, entity, EntityOperation.Delete);
        }
        #endregion

        #region Permission
        [WebMethod]
        public ResultInfo GetTopurlPermission(string account, string password, int roleOrLevel, AccountTypeValue accountType)
        {
            return GetInstance<WeburlTopMaster>().GetPermission(account, password, roleOrLevel, accountType);
        }

        [WebMethod]
        public ResultInfo UpdateTopurlPermission(string account, string password, int roleOrLevel, AccountTypeValue accountType, string topurlId)
        {
            int[] spliteIds = string.IsNullOrEmpty(topurlId) ? new int[] { } : topurlId.Split(',').Select(t => Convert.ToInt32(t)).ToArray();
            return GetInstance<WeburlTopMaster>().UpdatePermission(account, password, roleOrLevel, accountType, spliteIds);
        }

        [WebMethod]
        public ResultInfo GetSuburlPermission(string account, string password, int roleOrLevel, AccountTypeValue accountType)
        {
            return GetInstance<WeburlMaster>().GetPermission(account, password, roleOrLevel, accountType);
        }

        [WebMethod]
        public ResultInfo UpdateSuburlPermission(string account, string password, int roleOrLevel, AccountTypeValue accountType, string suburlId)
        {
            int[] spliteIds = string.IsNullOrEmpty(suburlId) ? new int[] { } : suburlId.Split(',').Select(t => Convert.ToInt32(t)).ToArray();
            return GetInstance<WeburlMaster>().UpdatePermission(account, password, roleOrLevel, accountType, spliteIds);
        }
        #endregion
    }
}
